/**
 * Project Name:spring-cloud-pilot File Name:ClassPathFileChangeListener.java Package Name:org.spring.cloud.pilot.jar
 * Date:2019年10月25日上午9:40:11 Copyright (c) 2019, dengqian37@126.com All Rights Reserved.
 *
 */

package org.spring.cloud.pilot.jar;

import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spring.cloud.pilot.configuration.EndpointAutoConfiguration;
import org.spring.cloud.pilot.filewatch.ChangedFiles;
import org.spring.cloud.pilot.filewatch.FileChangeListener;
import org.spring.cloud.pilot.listener.PromoteChangeEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.util.Assert;

/**
 * ClassName:ClassPathFileChangeListener <br/>
 * Function: TODO ADD FUNCTION. <br/>
 * Reason: TODO ADD REASON. <br/>
 * Date: 2019年10月25日 上午9:40:11 <br/>
 * 
 * @author dengqian
 * @version
 * @since JDK 1.8
 * @see
 */
public class ClassPathFileChangeListener implements FileChangeListener {

    private static final Logger LOGGER = LoggerFactory.getLogger(EndpointAutoConfiguration.class);

    private final ApplicationEventPublisher eventPublisher;

    public ClassPathFileChangeListener(ApplicationEventPublisher eventPublisher) {
        Assert.notNull(eventPublisher, "EventPublisher must not be null");
        this.eventPublisher = eventPublisher;

    }

    @Override
    public void onChange(Set<ChangedFiles> changeSet) {
        publishEvent(null);
    }

    private void publishEvent(PromoteChangeEvent event) {
        LOGGER.info("publishEvent");

        this.eventPublisher.publishEvent(new PromoteChangeEvent(this));

    }
}
